package edu.zut.main.thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class ThreadDemo3 {
    public static void main(String[] args) {
        ImgThread imgThread = new ImgThread("https://image.baidu.com/search/detail?ct=503316480&z=&tn=baiduimagedetail&ipn=d&word=%E7%A8%8B%E5%BA%8F%E5%91%98&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=-1&hd=&latest=&copyright=&cs=4250677112,3305739441&os=635497485,2745873908&simid=4290252295,724957888&pn=24&rn=1&di=140140&ln=1273&fr=&fmq=1630670361205_R&ic=&s=undefined&se=&sme=&tab=0&width=&height=&face=undefined&is=0,0&istype=2&ist=&jit=&bdtype=0&spn=0&pi=0&gsm=0&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252F5b0988e595225.cdn.sohucs.com%252Fq_mini%252Cc_zoom%252Cw_640%252Fimages%252F20170929%252Fe28345e8e98b4d7e80cea28586415e47.jpeg%26refer%3Dhttp%253A%252F%252F5b0988e595225.cdn.sohucs.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Djpeg%3Fsec%3D1633262361%26t%3D04deca845c11ca1f7948f9f50ed79d8e&rpstart=0&rpnum=0&adpicid=0&nojc=undefined", "3.jpg");
        ImgThread imgThread2 = new ImgThread("https://image.baidu.com/search/detail?ct=503316480&z=&tn=baiduimagedetail&ipn=d&word=%E7%A8%8B%E5%BA%8F%E5%91%98&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=-1&hd=&latest=&copyright=&cs=352655194,2084061379&os=594036731,1895999485&simid=0,0&pn=25&rn=1&di=141680&ln=1273&fr=&fmq=1630670361205_R&ic=&s=undefined&se=&sme=&tab=0&width=&height=&face=undefined&is=0,0&istype=2&ist=&jit=&bdtype=0&spn=0&pi=0&gsm=0&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%253A%252F%252Fimages2015.cnblogs.com%252Fnews%252F66372%252F201704%252F66372-20170424000548507-980759622.jpg%26refer%3Dhttp%253A%252F%252Fimages2015.cnblogs.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Djpeg%3Fsec%3D1633262361%26t%3D6f46ca9a16bcd1fe5d1cdb406603a9ba&rpstart=0&rpnum=0&adpicid=0&nojc=undefined", "4.jpg");

        //启动子线程
        new Thread(imgThread).start();
        new Thread(imgThread2).start();

    }
}
//创建一个子线程用于下载图片

/**
 * 创建线程的第二种方式
 * 1、实现Runnable接口
 * 2、实现run方法
 * 3、实例化当前线程类
 * 4、new Thread(Runnable able);
 */
class ImgThread implements Runnable{

    private String url;
    private String fileName;

    public ImgThread(String url,String fileName){
        this.url = url;
        this.fileName = fileName;
    }

    @Override
    public void run() {
        new ImgDown().down(url,fileName);
        System.out.println("下载了"+fileName);
    }
}







